<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="utf-8">
    <title>数链列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="./layui/css/layui.css" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" href="./style/admin.css" th:href="@{/style/admin.css}" media="all">
    <link rel="stylesheet" href="./style/myself.css" th:href="@{/style/myself.css}" media="all">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="./js/html5.min.js" th:src="@{/js/html5.min.js}"></script>
    <script src="./js/respond.min.js" th:src="@{/js/respond.min.js}"></script>
    <![endif]-->
    <script type="text/javascript" charset="utf-8" th:inline="javascript">
        var ctxPath = /*[[@{/}]]*/'';
        var authority = [[${#authorization.expression('hasAuthority("超级管理员")')}]];
    </script>
</head>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <form class="layui-form-item" onsubmit="return false;">
                <div class="layui-inline">
                    <label class="layui-form-label">链路名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="showName" placeholder="请输入链路名称" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block" style="width: 182px;">
                        <select name="latestProcessStat">
                            <option value="">所有</option>
                            <option value="0">正常</option>
                            <option value="1">异常</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btnse layuiadmin-btn-useradmin" lay-submit lay-filter="list-table-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                    </button>
                    <button id="reset" type="reset" class="layui-btns">
                        <i class="layui-icon layui-icon-refresh-3 layuiadmin-button-btn"></i>重置</button>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table id="list-table" lay-filter="list-table"></table>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
            </script>
            <script type="text/html" id="list-table-toolbar">
                <div class="layui-btn-group" sec:authorize="hasAuthority('超级管理员')">
                    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchdel">
                        <i class="layui-icon layui-icon-delete"></i>删除
                    </button>
                </div>
            </script>
            <script type="text/html" id="list-table-toolbar-detail">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm layui-btn-xs" lay-event="detail"><i
                            class="layui-icon layui-icon-about"></i>查看详情</a>
                </div>
            </script>

            <!-- 异常次数显示告警 -->
            <script type="text/html" id="toolbar-abnormal">
                {{#  if(d.abnormal == 0){ }}
                <i>{{d.abnormal}}</i>
                {{#  }else if(d.abnormal != 0){ }}
                <a class="sb" style="cursor: pointer" lay-event="abnormals">{{d.abnormal}}</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>
<div id="divId" style="height:calc(100vh - 50px); width: 100%; display: none"></div>
<script src="./js/common.js" th:src="@{/js/common.js}" charset="utf-8"></script>
<script src="./js/jquery.min.js" th:src="@{/js/jquery.min.js}" charset="utf-8"></script>
<script src="./js/jquery.base64.js" th:src="@{/js/jquery.base64.js}" charset="utf-8"></script>
<script src="./layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script charset="utf-8" th:inline="javascript">

    layui.config({
        base: ctxPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'dropMenu'], function () {
        var jq = layui.$, admin = layui.admin, form = layui.form, table = layui.table, device = layui.device();
        console.log("==========from==========="+JSON.stringify(form.latestProcessStat))
        table.render({
            elem: '#list-table',
            url: ctxPath + 'dataLink/get-link-Latest-list',
            toolbar: '#list-table-toolbar',
            request: {
                pageName: 'current',//页码的参数名称，默认：page
                limitName: 'size' //每页数据量的参数名，默认：limit
            },
            response: {
                statusName: 'code', //规定数据状态的字段名称，默认：code
                statusCode: 200,//规定成功的状态码，默认：0
                msgName: 'msg',//规定状态信息的字段名称，默认：msg
                countName: 'count', //规定数据总数的字段名称，默认：count
                dataName: 'data' //规定数据列表的字段名称，默认：data
            },
            parseData: function (res) { //res 即为原始返回的数据
                console.log("==========res==========="+JSON.stringify(res))
                return {
                    'code': res.code, //解析接口状态
                    'msg': res.msg, //解析提示文本
                    'count': res.data.total, //解析数据长度
                    'data': res.data.records //解析数据列表
                };
            },

            done: function () {
                jq('[data-field="latestProcessStat"]').children().each(function () {
                    if (jq(this).text() === '0') {
                        jq(this).text('正常');
                    }
                    if (jq(this).text() === '1') {
                        jq(this).html('<span style="color: #FF4500;font-weight: bold;">异常</span>');
                    }
                });
            },

            cols: [
                [{
                    type: 'checkbox',
                    hide: !authority
                }, {
                    field: 'showName',
                    title: '链路名称',
                    minWidth: 80,
                    sort: !0
                }, {
                    field: 'latestProcessStat',
                    title: '状态',
                    minWidth: 50,
                    sort: !0
                },{
                    field: 'abnormal',
                    title: '异常次数',
                    toolbar: '#toolbar-abnormal',
                    minWidth: 50,
                    sort: !0
                }, {
                    field: 'latestCheckTime',
                    title: '检查时间',
                    minWidth: 80,
                    sort: !0
                },
                    {
                    title: '操作',
                    width: authority ? 140 : 100,
                    align: 'center',
                    fixed: (device.ios || device.android) ? false : 'right',
                    toolbar: '#list-table-toolbar-detail'
                }
                ]
            ],
            page: !0,
            limit: 15,
            limits: [10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100],
            height: 'full-180'
        });
        //监听搜索
        form.on('submit(list-table-search)', function (data) {
            // var field = data.field;
            // 获取分页对象
            let pager = {};

                pager.curr = 1; // 将当前页码重置为 1
                pager.limit = 15; // 将每页显示数量重置为当前的每页显示数量
            //执行重载
            table.reload('list-table', {
                page: pager,
                where: {
                    showName: data.field.showName,
                    latestProcessStat: data.field.latestProcessStat
                }
            });
        });

        form.on('submit(resetSerach)', function (data) {
            // 获取分页对象
            let pager = {};

                pager.curr = 1; // 将当前页码重置为 1
                pager.limit = 15; // 将每页显示数量重置为当前的每页显示数量

            //执行重载
            table.reload('list-table', {
                page: pager,
                where: {
                    showName: '',
                    latestProcessStat: ''
                }
            });
        });

        // 点击表头排序
        table.on('sort(list-table)', function (obj) {
            table.reload('list-table', {
                initSort: obj
            });
        });

        //头工具栏事件
        table.on('toolbar(list-table)', function (obj) {
            switch (obj.event) {
                case 'batchdel':
                    var checkStatus = table.checkStatus('list-table'), checkData = checkStatus.data; //得到选中的数据
                    if (checkData.length === 0) {
                        return layer.msg('请选择数据');
                    }
                    console.log("checkStatus:" + JSON.stringify(checkStatus))
                    layer.confirm('确定删除吗？', function (index) {
                        admin.req({
                            type: 'delete',
                            url: ctxPath + 'dataLink/deleteLinkLatest',
                            data: JSON.stringify(checkStatus.data),
                            dataType: 'json',
                            contentType: 'application/json;charset=utf-8',
                            headers: {
                                [[${_csrf.headerName}]]: [[${_csrf.token}]]
                            },
                            success: function (result) {
                                var data = result.data;
                                if (data === webConst.SUCCESS) {
                                    table.reload('list-table'); //数据刷新
                                    layer.msg('删除成功！', {icon: 6});
                                } else {
                                    layer.msg('删除失败！', {icon: 5, shift: 6});
                                }
                            },
                            error: function () {
                                layer.msg('系统错误！', {icon: 5, shift: 6});
                            }
                        });
                    });
                    break;
            }
        });

        //监听工具条
        table.on('tool(list-table)', function (obj) {
            var data = obj.data;
            console.log("showName:" + JSON.stringify(data.showName))
            localStorage.setItem("showName", data.showName)
            if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    title: '数链详情（' + data.showName + '）',
                    closeBtn: 1,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: ctxPath + 'dataLink/visioDetail',
                });
            }
            else if (obj.event === 'abnormals') {
                layer.open({
                    type: 2,
                    title: '告警详情（' + data.showName + '）',
                    closeBtn: 1,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: ctxPath + 'monitor-alarm-record/list',
                });
            }
        });


        // //监听工具条
        // table.on('tool(list-table)', function (obj) {
        //     var data = obj.data;
        //     console.log("showName:" + JSON.stringify(data.showName))
        //     localStorage.setItem("showName", data.showName)
        //     if (obj.event === 'abnormals') {
        //         layer.open({
        //             type: 2,
        //             title: '告警详情（' + data.showName + '）',
        //             closeBtn: 1,
        //             shadeClose: true,
        //             area: ['100%', '100%'],
        //             content: ctxPath + 'monitor-alarm-record/list',
        //         });
        //     }
        // });

    });
</script>
<style scoped="scoped">
    .sb:hover {
        color: #00b8ff;
        text-decoration: underline;
    }
</style>
</body>
</html>
